<?php

class Nuo_View_Helper_Page extends Zend_View_Helper_Abstract
{

	/**
	 * block parser engine
	 */
	protected $_parser = null;

	/**
	 * set a new parser
	 */
	public function setParser($parser)
	{
		$this -> _parser = $parser;
		return $this;
	}

	/**
	 * get parser parser engine
	 * @return Parser Engine
	 */
	public function getParser()
	{
		if (null == $this -> _parser)
		{
			$this -> _parser = new Nuo_View_Parser;
		}
		return $this -> _parser;
	}

	/**
	 * magic call method
	 * @return Nuo_View_Helper_Page
	 */
	public function page()
	{
		return $this;
	}

	/**
	 * @param string $section
	 * @param string $page_name
	 * @param string $side
	 * @param int $side_id
	 * @return string
	 */
	public function render($section, $page_name = null, $side = null, $site_id = null)
	{

		$content = '';

		$api = Nuo::getApi('Layout');

		$region = $api -> getStructure($section, $page_name, $side, $site_id);

		$content = $this -> getParser() -> parseRegion($region);

		// mark the column and test what happend.
		return $content;
	}

	/**
	 * @see Nuo_View_Parser
	 * @param array $block
	 * @return string xhtml
	 */
	public function block($block)
	{
		return $this -> getParser() -> parseBlock($block);
	}

	/**
	 * @see Nuo_View_Parser
	 * @param array $blocks
	 * @return string
	 */
	public function area($blocks)
	{
		return $this -> getParser() -> parseArea($blocks);
	}

}
